import React from 'react';
import {WingBlank, WhiteSpace} from 'antd-mobile';
import AuthingSSO from "@authing/sso";
import styles from "./Jump.css"
import {Link} from 'react-router-dom';
import {getMail} from "../api";

let auth = new AuthingSSO({
    appId: '5eab8407d0a3305417668a6e',
    appDomain: 'tongjixinli.authing.cn',
});

class Jump extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            selectedTab: 'blueTab',
            hidden: false,
            fullScreen: true,
        };
        this.login()
    }


    async login() {
        let res = await auth.trackSession();
        if (res.session) localStorage.setItem('userInfo', JSON.stringify(res.userInfo))
        else auth.login();
    }

    render() {
        return (
            <div className={styles.background} style={{position: 'fixed', height: '100%', width: '100%', top: 0}}>
                <WhiteSpace/>
                <WhiteSpace/>
                <WingBlank>
                    <div style={{textAlign: "center"}}>
                        <Link to="/story"><img className={styles.liImg}
                                               onTouchEnd={this.touchEnd.bind(this, "/img/tj/资源 19@2x.png")}
                                               onTouchStart={this.touchStart.bind(this, "/img/tj/资源 20@2x.png")}
                                               src='/img/tj/资源 19@2x.png'/></Link>
                    </div>
                    <div style={{textAlign: "center"}}>
                        <img className={styles.liImg}
                             onClick={this.handleMailClick}
                             onTouchEnd={this.touchEnd.bind(this, "/img/tj/资源 21@2x.png")}
                             onTouchStart={this.touchStart.bind(this, "/img/tj/资源 22@2x.png")}
                             src='/img/tj/资源 21@2x.png'/>
                    </div>
                    <div style={{textAlign: "center"}}>
                        <Link to="/question"><img className={styles.liImg}
                                                  onTouchEnd={this.touchEnd.bind(this, "/img/tj/资源 23@2x.png")}
                                                  onTouchStart={this.touchStart.bind(this, "/img/tj/资源 24@2x.png")}
                                                  src='/img/tj/资源 23@2x.png'/></Link>
                    </div>
                </WingBlank>
            </div>
        );
    }

    handleMailClick = async () => {
        let res = await getMail()
        if (res.data.exists) this.props.history.push("/mymail?sendtime=" + res.data.sendtime)
        else this.props.history.push("read")
    }
    touchStart = (src, e) => {
        e.target.src = src
    }
    touchEnd = (src, e) => {
        e.target.src = src
    }
}

export default Jump;
